﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Weiz.TaskManager.DBUtility;
using Weiz.TaskManager.Models;

namespace Weiz.TaskManager.DAL
{
   public  class ResourcesDAL
    {
       public bool Add(ResourcesModel model)
       {
           var sql = @"INSERT INTO [Resources]
           ([ID]
           ,[Path]
           ,[ProductID]
           ,[Remark]
           ,[IsDelete]
           ,[CreateDate]
           ,[FileName])
     VALUES
           (@ID
           ,@Path
           ,@ProductID
           ,@Remark
           ,@IsDelete
           ,getdate()
           ,@FileName)";

           object param = new
           {
               ID = model.ID,
               Path = model.Path,
               ProductID = model.ProductID,
               Remark = model.Remark,
               IsDelete = model.IsDelete,
               FileName = model.FileName
           };
           return SQLHelper.ExecuteNonQuery(sql, param) > 0;
       }


       public int GetFileNameCode(string productId)
       {
           var sql = @"SELECT count(*)
  FROM [Resources] where ProductID=@productId";

           object param = new { productId = productId };

           return SQLHelper.ExecuteScalar<int>(sql, param);
       }



       public int isExitsResources(string fileName,string id)
       {
           var sql = @"SELECT count(*)
  FROM [Resources] where FileName=@fileName and ProductID=@productId";

           object param = new { fileName = fileName, productId  = id};

           return SQLHelper.ExecuteScalar<int>(sql, param);
       }
    }
}
